package com.kunya.product.service.impl.active;

import com.kunya.common.common.ResponseCode;
import com.kunya.common.common.ServerResponse;
import com.kunya.product.dao.active.ProductRecommendMapper;
import com.kunya.product.po.ProductRecommend;
import com.kunya.product.service.active.IProductRecommendService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WangGang
 * @Description: 推荐商品service实现类
 * @date 2018/7/7 11:40
 */
@Service("iProductRecommendService")
public class ProductRecommendServiceImpl implements IProductRecommendService {
    @Autowired
    private ProductRecommendMapper productRecommendMapper;
    /**
     * @Author WangGang
     * @Description 根据商品ID查找推荐商品表list
     * @Date 11:45 2018/7/7
     **/
    @Override
    public ServerResponse<List<ProductRecommend>> getProductRecoById(Long productId, String tablePrefix) {
        if(productId==null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(), "参数错误");
        }
        List<ProductRecommend> productRecommendList=productRecommendMapper.getProductRecommendById(productId,tablePrefix);
        if (CollectionUtils.isEmpty(productRecommendList)) {
            return ServerResponse.createByErrorMessage("推荐商品不存在");
        }
        return ServerResponse.createBySuccess(productRecommendList);
    }
    /**
     * @Author WangGang
     * @Description 根据推荐位ID查找显示推荐商品
     * @Date 13:42 2018/7/7
     **/
    @Override
    public ServerResponse<List<ProductRecommend>> getListByRecommendId(Long recommendId, String tablePrefix) {
        if(recommendId==null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),"参数错误");
        }
        List<ProductRecommend>  list=productRecommendMapper.listByRecommendId(recommendId,tablePrefix);
        if(CollectionUtils.isEmpty(list)){
            return ServerResponse.createByErrorMessage("推荐商品不存在");
        }
        return ServerResponse.createBySuccess(list);
    }
}
